﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using Microsoft.SharePoint;
using Eneta.Portal.Common.Definitions;
using Eneta.Portal.Common.Repository;
using System.Web.UI.WebControls;

namespace Eneta.Portal.Admin.Controls
{
    public class AdminLiteratureListControl : UserControl
    {
        //TODO: Rename file
        protected Label noAdminLiteratureLabel;
        protected Repeater adminLiteratureRepeater;

        public string WebUrl
        {
            get;
            set;
        }

        public string NoItemsLabelText
        {
            get { return this.noAdminLiteratureLabel.Text;  }
            set { this.noAdminLiteratureLabel.Text = value; }
        }

        public string ContentTypeName
        {
            get;
            set;
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            
            this.noAdminLiteratureLabel.Visible = false;
            
            BindLiterature();
        }

        private void BindLiterature()
        {
            var web = SPContext.Current.Web;
            var repository = new LiteratureRepository(web);
            var literatureItems = repository.GetPendingLiteratureItems(WebUrl, ContentTypeName);

            if (literatureItems.Count == 0)
            {
                this.noAdminLiteratureLabel.Visible = true;
                return;
            }
            this.adminLiteratureRepeater.DataSource = literatureItems;
            this.adminLiteratureRepeater.DataBind();
        }
    }
}
